package cn.sc.summer.redis.redisson.config;

import cn.sc.summer.redis.redisson.RedissonLock;
import cn.sc.summer.redis.redisson.RedissonManager;
import cn.sc.summer.redis.redisson.property.RedissonProperties;
import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author a-xin
 * @Description: Redisson自动化配置
 * @date 2019/6/19 下午11:55
 */
@Slf4j
@Configuration
@ConditionalOnClass(Redisson.class)
@EnableConfigurationProperties(RedissonProperties.class)
public class RedissonAutoConfiguration {

    @Bean
    @Primary
    public RedissonLock redissonLock(RedissonProperties redissonProperties) {
        RedissonManager redissonManager = new RedissonManager(redissonProperties);
        log.info("==> [Redisson Manager] is assembled, the current connection method is : " + redissonProperties.getType() + ", Connection address: " + redissonProperties.getHost() + ":" + redissonProperties.getPort());
        RedissonLock redissonLock = new RedissonLock(redissonManager);
        log.info("==> [Redisson Lock] is assembled!");
        return redissonLock;
    }

}

